//
//  YAYICalendarCell.m
//  testForAreacode
//
//  Created by Veer on 16/6/5.
//  Copyright © 2016年 Veer. All rights reserved.
//

#import "YAYICalendarCell.h"

#import "YAYICalendarModel.h"

#define WeekArray @[@"日", @"一", @"二", @"三", @"四", @"五", @"六"]


@interface YAYICalendarCell()

@property (nonatomic, weak) UILabel *weekLbl;
@property (nonatomic, weak) UIView *circleBgView;
@property (nonatomic, weak) UILabel *dayLbl;

@end

@implementation YAYICalendarCell


- (void)setModel:(YAYICalendarModel *)model
{
    _model = model;
    
    self.weekLbl.text = WeekArray[model.week - 1];
    self.dayLbl.text = [NSString stringWithFormat:@"%ld", model.day];
    
    if (model.isToday) {
        self.circleBgView.hidden = NO;
    }else{
        self.circleBgView.hidden = YES;
    }
    
    if (model.week == 1 || model.week == 7) {
        self.weekLbl.textColor = YAYIColor(244, 37, 43);
        self.dayLbl.textColor = YAYIColor(244, 37, 43);
    }else{
        self.weekLbl.textColor = YAYIColor(112, 108, 108);
        self.dayLbl.textColor = [UIColor blackColor];
        
        if (model.isToday) {
            self.dayLbl.textColor = [UIColor whiteColor];
        }else{
            self.dayLbl.textColor = [UIColor blackColor];
        }
    }
}


+ (instancetype)cellWith:(UITableView *)tablevie
{
    static NSString *cellID = @"YAYICalendarCell";
    
    YAYICalendarCell *cell = [tablevie dequeueReusableCellWithIdentifier:cellID];
    
    if (nil == cell) {
        cell = [[YAYICalendarCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
        
    }
    return cell;
}


-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self setupSubView];
    }
    return  self;
}


- (void)setupSubView
{
    UILabel *weekLbl = [[UILabel alloc] init];
    weekLbl.font = [UIFont systemFontOfSize:16];
    weekLbl.textColor = YAYIColor(112, 108, 108);
    weekLbl.textAlignment = NSTextAlignmentCenter;
    [self.contentView addSubview:weekLbl];
    self.weekLbl = weekLbl;
    
    UIView *circleBgView = [[UIView alloc] init];
    circleBgView.backgroundColor = YAYIColor(104, 174, 240);
    circleBgView.layer.masksToBounds = YES;
    circleBgView.hidden = YES;
    [self.contentView addSubview:circleBgView];
    self.circleBgView = circleBgView;
    
    UILabel *dayLbl = [[UILabel alloc] init];
    dayLbl.font = [UIFont systemFontOfSize:16];
    dayLbl.textAlignment = NSTextAlignmentCenter;
    [self.contentView addSubview:dayLbl];
    self.dayLbl = dayLbl;
}


- (void)layoutSubviews
{
    [super layoutSubviews];
    
    [self.weekLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.contentView);
        make.centerY.mas_equalTo(self.contentView.mas_centerY).multipliedBy(0.5);
    }];
    
    [self.dayLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.contentView);
        make.centerY.mas_equalTo(self.contentView.mas_centerY).multipliedBy(1.5);
    }];
    
    [self.circleBgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.mas_equalTo(self.dayLbl);
        make.width.height.mas_equalTo(24);
    }];
    self.circleBgView.layer.cornerRadius = 12;
}


@end
